﻿using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace Logger.ViewModels
{
    public enum LogLevel
    {
        Info, Warning, Error
    }
    public partial class LogEntry : ObservableObject
    {
        public DateTime Timestamp { get; set; }
        public string? Message { get; set; }

        [ObservableProperty]
        public LogLevel logLevel;

        public string DisplayText => $"[{Timestamp:yyyy-MM-dd HH:mm:ss}] {Message}";

        [ObservableProperty]
        public ObservableCollection<LogEntry> _logs = new ObservableCollection<LogEntry>();

        public void Log(string message, LogLevel logLevel = LogLevel.Info)
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                Logs.Add(new LogEntry { Timestamp = DateTime.Now, Message = message, LogLevel = logLevel });
            });

        }

    }
}
